define(function( require ) {
    var Backbone = require('backbone');

    var utils = require('core/utils');
    return Backbone.Model.extend({
        sync: function(options) {
            var that = this;
            if ($.trim(this.get('src')) == '') {
                return;
            }

            var data = {
                attachment_url: this.get('src'),
                media_type: 'image',
                v: 2,
                mp_id: window._global.kdt_id
            };

            $.post(window._global.url.img + '/download?format=json', data, function(response) {
                if (!response.success) {
                    utils.errorNotify('出错啦，请重试。');
                    return;
                }
                window.NC.trigger('image:download:success', [response.success]);
                if (options && _.isFunction(options.success)) {
                    options.success(response.success);
                }
            }, 'json').always(function() {
                if (options && _.isFunction(options.always)) {
                    options.always();
                }
                that.clearDownload();
            }).fail(function() {
                utils.errorNotify('网络出现错误啦。');
            });
            return true;
        },
        clearDownload: function() {
            this.set('src', '');
        }
    });
});